<script setup lang="ts">
/*
 * @description:列表 会员表
 * @author: lxx
 * @date: 2025-7-22
 * @version: V1.0.0
 */
import { dataPageApi, dataBatchDelApi } from '@/api/member'
import type { ItemFormInt } from '@/api/member/types'
import AddEditForm from './AddEditForm.vue'
import { usePage } from '@/hooks/system/useFramework'
import constants from '@/common/constant'
const router = useRouter()
/* 查询参数*/
const queryParams = ref({
  keywords: ''
})
/* 查询的FormRef*/
const queryFormRef = ref()
/* 新增编辑FormRef*/
const addEditFormRef = ref()
const { queryPage, tableData, loading, handleQuery, handleResetQuery, handleAddEdit, handleDelete, handleSelectChange } = usePage<ItemFormInt>(
  dataPageApi,
  dataBatchDelApi,
  queryParams,
  queryFormRef,
  addEditFormRef
)
</script>
<template>
  <div class="web-container-box flex-start-start column">
    <!-- 搜索区域 -->
    <div class="search-container">
      <el-card shadow="hover">
        <el-form ref="queryFormRef" :model="queryParams" :inline="true">
          <el-form-item label="关键字" prop="keywords">
            <el-input v-model="queryParams.keywords" placeholder="姓名/电话" clearable @keyup.enter="handleQuery" />
          </el-form-item>
          <el-form-item class="search-buttons">
            <el-button type="primary" icon="search" @click="handleQuery">搜索</el-button>
            <el-button icon="refresh" @click="handleResetQuery">重置</el-button>
            <el-button type="success" icon="plus" @click="handleAddEdit('add')">新增</el-button>
            <el-button type="danger" icon="delete" @click="handleDelete()">删除</el-button>
          </el-form-item>
        </el-form>
      </el-card>
    </div>
    <!-- 列表 -->
    <el-card shadow="hover" class="data-table">
      <el-table fit v-loading="loading"  max-height="680" width="100%" highlight-current-row :data="tableData" border @selection-change="handleSelectChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="姓名" prop="username" />
        <el-table-column label="电话" prop="phone">
          <template #default="scope">
            {{ scope.row.phone || '暂无' }}
          </template>
        </el-table-column>
        <el-table-column label="性别" prop="sex">
          <template #default="scope">
            <dict-label :code="constants.SEX" :model-value="scope.row.sex" />
          </template>
        </el-table-column>
        <!-- <el-table-column label="会员等级" prop="memberlevel" />
        <el-table-column label="余额" prop="balance" /> -->
        <el-table-column fixed="right" label="操作" align="center" width="170">
          <template #default="scope">
            <el-button type="primary" link size="small" icon="edit" @click.stop="handleAddEdit('edit', scope.row)">编辑</el-button>
            <el-button type="danger" link size="small" icon="delete" @click.stop="handleDelete(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        v-if="queryPage.total > 0"
        layout="prev, pager, next, sizes, total"
        :total="queryPage.total"
        v-model:current-page="queryPage.pageNum"
        v-model:page-size="queryPage.pageSize"
        @current-change="handleQuery"
        @size-change="handleQuery"
      />
    </el-card>
    <!-- 新增、编辑弹窗 -->
    <AddEditForm ref="addEditFormRef"></AddEditForm>
  </div>
</template>
<style lang="scss" scoped></style>
